import utime
import modbus as mb
import yuanda_htb485


#初始化
def mb_init():
    ret = mb.init('modbus_485_4800')
    if ret < 0:
        raise ValueError("init modbus failed.")

'''
获取htb变送器温度,湿度,光照数据
htb变送器地址默认为1
'''
def test_htb485():
    htb485Obj = yuanda_htb485.HTB485(mb, 1)
    humidity = htb485Obj.getHumidity()
    temperature =  htb485Obj.getTemperature()
    brightness = htb485Obj.getBrightness()
    htb = htb485Obj.getHTB()
    
    print("temperature:", temperature/10,"℃")
    print("humidity:", humidity,"%RH")
    print("brightness:",brightness,"lx")
    print("htb:",htb)


if __name__ == '__main__':
    mb_init()
    while True:
        test_htb485()
        utime.sleep(1)
    #mb.deinit()



